package com.example.lenovo.a203_yhy_ordering_3.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.lenovo.a203_yhy_ordering_3.R;
import com.example.lenovo.a203_yhy_ordering_3.beans.AllUserCollectBean;
import com.example.lenovo.a203_yhy_ordering_3.beans.FoodListBean;
import com.example.lenovo.a203_yhy_ordering_3.beans.UserCollectShopBean;
import com.example.lenovo.a203_yhy_ordering_3.viewholder.CollectViewHolder;
import com.example.lenovo.a203_yhy_ordering_3.viewholder.FoodListViewHolder;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by lenovo on 2018/12/5.
 */

public class CollectShopAdapter extends RecyclerView.Adapter<CollectViewHolder> {
    private List<AllUserCollectBean> list;

    OnItemClickListener mOnItemClickListener;
    public interface OnItemClickListener{
        void onItemClick(View view, int position);
    }

    public void setOnItemClickListener(OnItemClickListener listener){
        mOnItemClickListener=listener;
    }

    @NonNull
    @Override
    public CollectViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        LayoutInflater layoutInflater = LayoutInflater.from(viewGroup.getContext());
        View view = layoutInflater.inflate(R.layout.collect_item,viewGroup,false);
        CollectViewHolder viewHolder = new CollectViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull CollectViewHolder collectViewHolder, final int i) {
        final AllUserCollectBean allUserCollectBean = list.get(i);

        collectViewHolder.textView1.setText(allUserCollectBean.getShopname());
        collectViewHolder.textView2.setText(allUserCollectBean.getAddress());

        Picasso.get()
                .load("http://172.24.10.175:8080/foodService"+allUserCollectBean.getPic())
                .into(collectViewHolder.imageView);

        collectViewHolder.view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickListener.onItemClick(v,i);
            }
        });
    }

    @Override
    public int getItemCount() {
        if(list!=null)
            return list.size();
        else
            return 0;
    }

    //自定义 设置数据list
    public void setList(List<AllUserCollectBean> list)
    {
        this.list=list;
        notifyDataSetChanged();//通知RV刷新数据
    }


}
